#include <iostream>
#include <vector>
using namespace std;

//已知军舰只能纵向或者横向摆放，因此需要计算的只有横着连续的或纵向连续的独立部分。

class Solution
{
public:
    int countBattleships(vector<vector<char>> &board)
    {
        int count = 0;
        for (int i = 0; i < board.size(); i++)
        {
            for (int j = 0; j < board[0].size(); j++)
            {
                if (board[i][j] == 'X' && (i == 0 || board[i - 1][j] == '.') && (j == 0 || board[i][j - 1] == '.'))
                    count++;
            }
        }
        return count;
    }
};